//
// Created by zengyuhao on 25-4-30.
//

#ifndef ZORAL_UTILITIES_H
#define ZORAL_UTILITIES_H

#include <stdexcept>
#include <vector>

template<typename T>
std::vector<std::vector<T>> Transpose(const std::vector<std::vector<T>> &input)
{
    if (input.empty())
        return {};

    size_t rows = input.size();
    size_t cols = input[0].size();

    std::vector<std::vector<T>> result(cols, std::vector<T>(rows));

    for (size_t i = 0; i < rows; ++i)
    {
        if (input[i].size() != cols)
        {
            throw std::invalid_argument("All rows must have the same number of columns");
        }
        for (size_t j = 0; j < cols; ++j)
        {
            result[j][i] = input[i][j];
        }
    }

    return result;
}


#endif // ZORAL_UTILITIES_H
